function [output]=figure_optimallocalcorrelations()
numpoints = 800;
x1 = randint(1,numpoints,[20,80]);
y1 = x1.*2;
x1 = x1 + randn(1,numpoints).*2.0;
y1 = y1 + randn(1,numpoints).*5.0;
y1 = y1 - 100;
subnumpoints2 = numpoints/2;
x2 = randint(1,subnumpoints2,[35,70]);
y2 = x2.*(-8.5)+500;
x2 = x2 + randn(1,subnumpoints2).*2.0;
y2 = y2 + randn(1,subnumpoints2).*3.5;
subnumpoints3 = numpoints/2;
x3 = randint(1,subnumpoints3,[25,60]);
y3 = x3.*(8.5)-400;
x3 = x3 + randn(1,subnumpoints3).*2.0;
y3 = y3 + randn(1,subnumpoints3).*3.5;
x3 = x3 - 15;
minx = min([x1,x2,x3]); 
maxx = max([x1,x2,x3]);
miny = min([y1,y2,x3]);
maxy = max([y1,y2,x3]);
xn = rand(1,int32(numpoints/12)).*(maxx-minx)+minx;
yn = rand(1,int32(numpoints/12)).*(maxy-miny)+miny;
x = [x1,x2,x3,xn];
y = [y1,y2,y3,yn];
plot(x,y,'+', 'MarkerSize',2);
hold on;
drawellipse(50,0,10,90,-pi/7.5);
hold on;
drawellipse(30,-20,5,190,-pi/30);
hold on;
drawellipse(52,58,5,180,pi/28);

function drawellipse(cx,cy,rx,ry,rotate)
alpha=linspace(0,2*pi,200);
x=rx*cos(alpha);
y=ry*sin(alpha);
phi=rotate;%angle of rotation in radians
xyr=[cos(phi) -sin(phi);sin(phi) cos(phi)]*[x(:) y(:)]';
plot(cx+xyr(1,:),cy+xyr(2,:),'r--','LineWidth',2);
